package com.yndsoft.jc.supplier.adapter;

import android.content.Context;
import android.view.View;

import com.yndsoft.jc.R;
import com.yndsoft.jc.supplier.model.AddressModel;
import com.yndsoft.jc.supplier.widget.popupwindow.OnChooseAddressListener;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerAdapter;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerHolder;
import com.yndsoft.jc.supplier.widget.recyclerview.RecyclerListener;

import java.util.List;

public class AddressAdapter extends RecyclerAdapter<AddressModel> implements RecyclerListener.OnClickListener<RecyclerHolder> {

    private OnChooseAddressListener listener;
    private String level;

    public void setOnChooseAddressListener(OnChooseAddressListener listener) {
        this.listener = listener;
    }

    public AddressAdapter(Context context, List<AddressModel> data, String level) {
        super(context, data, R.layout.item_address);
        this.level = level;
    }

    @Override
    public void convert(RecyclerHolder holder, AddressModel model) {
        holder.setTvText(R.id.name, model.getValue());
        holder.setOnClickListener(this, R.id.name);
    }

    @Override
    public void onClick(View v, int position, RecyclerHolder holder) {
        AddressModel addressModel = mData.get(position);
        if (addressModel != null) {
            if (listener != null) {
                listener.onChooseAddress(addressModel.getKey(), addressModel.getValue(), level);
            }
        }
    }
}